#ifndef __STORMWIDGET_STORMWIDGET_UILIBRARY_CACTIVEXFRAMEWND_ACTIVEXFRAMEWND_H
#define __STORMWIDGET_STORMWIDGET_UILIBRARY_CACTIVEXFRAMEWND_ACTIVEXFRAMEWND_H

class CActiveXFrameWnd : public IOleInPlaceFrame
{
public:
	CActiveXFrameWnd(CActiveXUI* pOwner) : m_dwRef(1), m_pOwner(pOwner), m_pActiveObject(NULL)
	{
	}
	~CActiveXFrameWnd()
	{
		if( m_pActiveObject != NULL ) m_pActiveObject->Release();
	}

	ULONG m_dwRef;
	CActiveXUI* m_pOwner;
	IOleInPlaceActiveObject* m_pActiveObject;

	// IUnknown
	STDMETHOD_(ULONG,AddRef)()
	{
		return ++m_dwRef;
	}
	STDMETHOD_(ULONG,Release)()
	{
		ULONG lRef = --m_dwRef;
		if( lRef == 0 ) delete this;
		return lRef;
	}
	STDMETHOD(QueryInterface)(REFIID riid, LPVOID *ppvObject)
	{
		*ppvObject = NULL;
		if( riid == IID_IUnknown ) *ppvObject = static_cast<IOleInPlaceFrame*>(this);
		else if( riid == IID_IOleWindow ) *ppvObject = static_cast<IOleWindow*>(this);
		else if( riid == IID_IOleInPlaceFrame ) *ppvObject = static_cast<IOleInPlaceFrame*>(this);
		else if( riid == IID_IOleInPlaceUIWindow ) *ppvObject = static_cast<IOleInPlaceUIWindow*>(this);
		if( *ppvObject != NULL ) AddRef();
		return *ppvObject == NULL ? E_NOINTERFACE : S_OK;
	}  
	// IOleInPlaceFrameWindow
	STDMETHOD(InsertMenus)(HMENU /*hmenuShared*/, LPOLEMENUGROUPWIDTHS /*lpMenuWidths*/)
	{
		return S_OK;
	}
	STDMETHOD(SetMenu)(HMENU /*hmenuShared*/, HOLEMENU /*holemenu*/, HWND /*hwndActiveObject*/)
	{
		return S_OK;
	}
	STDMETHOD(RemoveMenus)(HMENU /*hmenuShared*/)
	{
		return S_OK;
	}
	STDMETHOD(SetStatusText)(LPCOLESTR /*pszStatusText*/)
	{
		return S_OK;
	}
	STDMETHOD(EnableModeless)(BOOL /*fEnable*/)
	{
		return S_OK;
	}
	STDMETHOD(TranslateAccelerator)(LPMSG /*lpMsg*/, WORD /*wID*/)
	{
		return S_FALSE;
	}
	// IOleWindow
	STDMETHOD(GetWindow)(HWND* phwnd)
	{
		if( m_pOwner == NULL ) return E_UNEXPECTED;
		*phwnd = m_pOwner->GetManager()->GetPaintWindow();
		return S_OK;
	}
	STDMETHOD(ContextSensitiveHelp)(BOOL /*fEnterMode*/)
	{
		return S_OK;
	}
	// IOleInPlaceUIWindow
	STDMETHOD(GetBorder)(LPRECT /*lprectBorder*/)
	{
		return S_OK;
	}
	STDMETHOD(RequestBorderSpace)(LPCBORDERWIDTHS /*pborderwidths*/)
	{
		return INPLACE_E_NOTOOLSPACE;
	}
	STDMETHOD(SetBorderSpace)(LPCBORDERWIDTHS /*pborderwidths*/)
	{
		return S_OK;
	}
	STDMETHOD(SetActiveObject)(IOleInPlaceActiveObject* pActiveObject, LPCOLESTR /*pszObjName*/)
	{
		if( pActiveObject != NULL ) pActiveObject->AddRef();
		if( m_pActiveObject != NULL ) m_pActiveObject->Release();
		m_pActiveObject = pActiveObject;
		return S_OK;
	}
};

#endif //__STORMWIDGET_STORMWIDGET_UILIBRARY_CACTIVEXFRAMEWND_ACTIVEXFRAMEWND_H